﻿using System;
using System.Configuration;

namespace Eksponent.CropUp.Config
{
    public class CropUpSection  : ConfigurationSection
    {
        [ConfigurationProperty("urlPrefix", DefaultValue = "~/CropUp/", IsRequired = false)]
        public string UrlPrefix
        {
            get { return (string)this["urlPrefix"]; }         
        }

        [ConfigurationProperty("cachePath", DefaultValue = "~/App_Data/ImageCache", IsRequired = false)]
        [Obsolete("CropUp doesn't do caching anymore")]
        public string CachePath
        {
            get { return (string)this["cachePath"]; }            
        }

        [ConfigurationProperty("roots")]
        [Obsolete("These aren't used anymore")]
        public NameValueConfigurationCollection Roots
        {
            get { return (NameValueConfigurationCollection)this["roots"]; }            
        }

        [ConfigurationProperty("autoDetect", DefaultValue = true, IsRequired = false)]        
        public bool AutoDetect
        {
            get { return (bool)this["autoDetect"]; }        
        }

        [ConfigurationProperty("detectFaces", DefaultValue = true, IsRequired = false)]        
        public bool DetectFaces
        {
            get { return (bool)this["detectFaces"]; }
        }

        [ConfigurationProperty("boxFaces", DefaultValue = true, IsRequired = false)]
        public bool BoxFaces
        {
            get { return (bool)this["boxFaces"]; }
        }

        [ConfigurationProperty("faceMargin", DefaultValue = "150", IsRequired = false)]
        public int FaceMargin
        {
            get { return int.Parse("" + this["faceMargin"]); }
        }

        [ConfigurationProperty("cacheCropData", DefaultValue = true, IsRequired = false)]
        public bool CacheCropData
        {
            get { return (bool)this["cacheCropData"]; }
        }

        [ConfigurationProperty("iis6", DefaultValue = false, IsRequired = false)]
        public bool UseLegacyUrls
        {
            get { return (bool)this["iis6"]; }
        }


        [ConfigurationProperty("referenceWidth", DefaultValue = "1024", IsRequired = false)]
        public int ReferenceWidth
        {
            get { return int.Parse("" + this["referenceWidth"]); }            
        }



        [ConfigurationProperty("referenceHeight", DefaultValue = "768", IsRequired = false)]
        public int ReferenceHeight
        {
            get { return int.Parse("" + this["referenceHeight"]); }            
        }

        [ConfigurationProperty("croppings", IsRequired = false)]
        public CropInfoCollection CropInfos
        {
            get { return (CropInfoCollection) this["croppings"]; }
        }
    }
}
